import { useState, useCallback } from 'react';
import { message } from 'antd';
import { getRecord } from '../services/formContent';

export default function useFormValues() {
  const [data, setData] = useState(null);

  const getFormValues = useCallback((formType, id) => {
    if (formType !== 'add') {
      getRecord({ id }).then(res => {
        if (res?.success) {
          setData(res.data);
        } else {
          message.warn('获取信息失败，请重试');
        }
      });
    } else {
      setData(null);
    }
  }, []);

  return {
    data,
    setData,
    getFormValues,
  };
}
